//
//  ViewController.m
//  MusouKit
//
//  Created by danal on 13-3-19.
//  Copyright (c) 2013年 danal. All rights reserved.
//

#import "ViewController.h"
#import "View.h"

@interface ViewController ()

@end

@implementation ViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    View *view = [[View alloc] initWithFrame:CGRectMake(100, 100, 200, 100)];
    view.backgroundColor = [UIColor clearColor];
    [self.view addSubview:view];
    [view release];
    
    [self addKeyboardObserver];
    
    UITextField *textfield = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 320, 44.f)];
    textfield.backgroundColor = [UIColor grayColor];
    textfield.tag = 10000;
    [self.view addSubview:textfield];
    [textfield release];
    
    return;
    
    NSString *path = [NSBundle pathForRes:@"urlXML.xml"];
    NSString *xml = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
    NSRegularExpression *reg = [NSRegularExpression regularExpressionWithPattern:@"src=\"(.+)\"" options:NSRegularExpressionCaseInsensitive error:nil];
    NSArray *matches = [reg matchesInString:xml options:NSMatchingReportCompletion range:NSMakeRange(0, [xml length])];
    float x = 0.f, y = 0.f , w = 50.f;
    int count = 0;
    for (NSTextCheckingResult *rs in matches){
        NSString *s = [xml substringWithRange:[rs rangeAtIndex:1]];
//        NSLog(@"%@",s);
        WebImageView *imageView = [[WebImageView alloc] initWithFrame:CGRectMake(x, y, w, w)];
        imageView.url = s;
        [self.view addSubview:imageView];
        [imageView release];
        y += w + 2.f;

        count++;
        if (count == 10) break;
    }
    [xml release];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (UIView *)keyboardAccessoryView{
    return [self.view viewWithTag:10000];
}

- (void(^)(void))keyboardDidShowBlock{
    void(^block)(void) = ^{
        ECHO(@"keyboard did show");
        
    };
    return block;
}

@end
